package com.fast.alden.admin.web.controller;

import com.fast.alden.admin.service.AuthService;
import com.fast.alden.common.entity.dto.LoginParam;
import com.fast.alden.common.entity.dto.LoginResult;
import com.fast.alden.common.entity.dto.VerifyCodeEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 认证与鉴权控制器
 */
@Tag(name = "AuthController", description = "授权管理")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private AuthService authService;

    @Operation(summary = "获取验证码")
    @GetMapping("/verify-code")
    public VerifyCodeEntity generateVerifyCode() throws IOException {
        return authService.generateVerifyCode();
    }

    @Operation(summary = "登录")
    @PostMapping("/login")
    public LoginResult login(@RequestBody @Validated LoginParam param) {
        return authService.login(param);
    }

    @Operation(summary = "注销登录")
    @PostMapping("/logout")
    public void logout() {
        authService.logout();
    }
}
